var client_selected=0;
var tableIndividual;
var tableLegal;
var server_path;
$(document).ready(function(){
		server_path = $("#server_path").val();
});
function edit_client(client){
	client_selected = client;
	sendData="get_client="+client;
	$.ajax({
		type: "POST",
		url: server_path+"libs/clients_ajax.php",
		data: sendData,
		dataType:'json',
		success: function(data){	
			console.log(['address']);
			if(data[0]['type']==0){
				$("#legal_inputs").hide();
			}else{
				$("#legal_inputs").show();
			}
			$.each(data[0],function(key,value){

				$('#'+key).val(value);
			});
			if(data[0]['terms_and_conditions']==1){
				$('input[type=radio][name=terms_and_conditions][value=1]').attr('checked',true);
			}else{
				$('input[type=radio][name=terms_and_conditions][value=0]').attr('checked',true);
			}
			$("#clients_tabs li :eq(1)").show();
			$("#clients_tabs li :eq(0)").trigger('click');
			$("#modal-clients-data").modal();
		}
	});

	
	
}

function open_add(val){
	if(val==1){
		$('#legal_inputs').show();
	}else{
		$('#legal_inputs').hide();
	}
	$("#clients_tabs li a:first").trigger('click');
	$("#clients_tabs li :eq(1)").hide();

	$('#client_form')[0].reset();
	$("#modal-clients-data").modal();
	client_selected=0;
}

function save_client(){
	if($("#site_page_tabs li:first").hasClass('active')){		
		val=0;
	}else{		
		val=1;
	}
	sendData = $("#client_form").serialize()+'&add_client='+client_selected+'&type='+val;
	
	$.ajax({
		type: "POST",
		url: server_path+"libs/clients_ajax.php",
		data: sendData,
		dataType:'json',
		success: function(data){	

		}
	});
}

function delete_client(client,obj,val){
	sendData = 'delete_client='+client;
	$.ajax({
		type: "POST",
		url: server_path+"libs/clients_ajax.php",
		data: sendData,
		
		success: function(data){	
			if(val==0){
				row = $(obj).closest("tr").get(0);
				tableIndividual.fnDeleteRow(tableIndividual.fnGetPosition(row));
				
			}else{
				row = $(obj).closest("tr").get(0);
				tableLegal.fnDeleteRow(tableLegal.fnGetPosition(row));
			}
		}
	});
}

$(document).ready(function(){
	
	tableIndividual=$("#individual_table").dataTable();
	tableLegal=$("#legal_table").dataTable();


});